package com.cityeye.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.hibernate.criterion.Order;

import com.cityeye.entity.Department;
import com.cityeye.entity.Issuetype;
import com.cityeye.entity.Patrol;
import com.cityeye.entity.Subissuetype;
import com.cityeye.search.SearchCriteria;

public class IssueTypeDao extends AbstractEntityDao<Issuetype>{

	private static SearchCriteria[] criteria;

	public Issuetype createNewEmptyEntity() {
		return new Issuetype();
	}
	
	public List<Subissuetype> loadSubIssues(Issuetype issue) {
		List<Subissuetype> result= new ArrayList<Subissuetype>();
		
		Issuetype dbissue = (Issuetype)sf.getCurrentSession().get(
				getEntityClass(), issue.getId());
		
		if(dbissue!=null){
			Set subIssues= dbissue.getSubissuetypes();
			result.addAll(subIssues);
		}
		
		return result;
	}

	public SearchCriteria[] getSearchCriteria() {
		if (criteria == null) {
			criteria = new SearchCriteria[] {
					new SearchCriteria("Code", SearchCriteria.VT_INT),
					new SearchCriteria("Name", SearchCriteria.VT_STRING),
					new SearchCriteria("Taxable", SearchCriteria.VT_STRING),
					new SearchCriteria("Mobile", SearchCriteria.VT_STRING) };
		}
		return criteria;
	}

	
	protected Class<Issuetype> getEntityClass(){
		return Issuetype.class;
	}

	protected Order getOrderField(){
		return Order.asc("name");
	}	
}
